package com.yanqu.road.server.cmd.activity.deepfishing;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.DeepFishingProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.deepseafishing.DeepFishingModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_DEEP_FISHING_START_GAME, desc = "深海觅诊开始游戏")
public class DeepFishingStartGameCmd extends AbstractCommand {

    private int acitivityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        DeepFishingProto.deepFishingStartReqMsg reqMsg = DeepFishingProto.deepFishingStartReqMsg.parseFrom(packet.getBytes());
        acitivityId = reqMsg.getActivityId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(DeepFishingModule.class).startFishingGame(acitivityId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            DeepFishingProto.deepFishingStartRespMsg.Builder builder = DeepFishingProto.deepFishingStartRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_DEEP_FISHING_START_GAME,builder);
        }
    }
}
